package top.easycode.app.controller.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.easycode.app.common.BaseReq;
import top.easycode.app.common.BaseRsp;
import top.easycode.app.constants.RespCode;
import top.easycode.app.controller.APPBaseService;
import top.easycode.app.controller.service.dto.req.CheckNameExitReq;
import top.easycode.app.controller.service.dto.rsp.CheckExitRsp;
import top.easycode.app.dao.UserInfoMapper;
import top.easycode.app.model.UserInfo;
import top.easycode.app.service.UserInfoService;
import top.easycode.app.util.DTOUtil;

/**
 * Created by hujun on 2017\9\30 0030.
 */
@Service
public class CheckNameExitService extends APPBaseService{
    @Autowired
    UserInfoService userInfoService;
    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    protected BaseReq parseContext(String context, String type) throws Exception {
        return DTOUtil.parseDTO(context, CheckNameExitReq.class,type);
    }

    @Override
    protected BaseRsp callPscService(BaseReq req, String... params) {
        CheckNameExitReq checkNameExitReq = (CheckNameExitReq)req;
        UserInfo userInfo= userInfoMapper.selectByName(checkNameExitReq.getName());
        CheckExitRsp rsp = new CheckExitRsp();
        rsp.setRespCode(RespCode.E_0000.getCode());
        rsp.setRespDesc(RespCode.E_0000.getName());
        if(userInfo != null){
            rsp.setExit(true);
        }else{
            rsp.setExit(false);
        }
        return rsp;
    }
}
